#include "intr.h"

#include <signal.h>

static sigset_t disabled, pending;

/**
 * Initialize the signal sets used.
 *     should be called in device_init_common.
 */
void
intr_init (void)
{
	sigemptyset (&disabled);
	sigaddset (&disabled, SIGIO);
}


/**
 * Enable signal-simulated irqs and check whether we have any pending 'interrupts'.
 */
void
intr_enable (void)
{
	sigprocmask (SIG_UNBLOCK, &disabled, 0);
	sigpending (&pending);
	if (sigismember (&pending, SIGIO))
		raise (SIGIO);
}


/**
 * Disable signal-simulated irqs.
 *     simulated irqs: SIGIO
 */
void
intr_disable (void)
{
	sigprocmask (SIG_BLOCK, &disabled, 0);
}
